<?php
/*************************************************************************
Class Pick_Dao_Slider
----------------------------------------------------------------
PICKCO CMS Project
Company: PICKCO  Co., Ltd  
Email: admin@pick.vn
Last updated: 15/07/2008
**************************************************************************/
class Pick_Dao_Slider extends Pick_Core_Objects {
	function Pick_Dao_Slider($database = '') {
		if(!$database) {
			global $db;
			$this->_db = $db;
		} else $this->_db = $database;
		$this->typeId = " AND typeid = 5";
		$this->objectInfo = "Pick_Dao_SliderInfo";
		$this->table = DB_PREFIX."product";		
	}	
/*-----------------------------------------------------------------------*
* Function: getObjectsFromCId
* Parameter: WHERE condition
* Return: Array of Info objects
*-----------------------------------------------------------------------*/
	function getObjectsFromCId($page = 1, $cid, $sort = array(), $items_per_page = DEFAULT_ADMIN_ROWS_PER_PAGE) {
		return $this->getObjects($page, 'cid = "' . $cid . '" AND status = 1', $sort, $items_per_page);
	}	
/*-----------------------------------------------------------------------*
* Function: getObjectsFromArrayId
* Parameter: WHERE condition
* Return: Array of Info objects
*-----------------------------------------------------------------------*/
	function getObjectsFromArrayCId($page = 1, $array_id = array(), $sort = array(), $items_per_page = DEFAULT_ADMIN_ROWS_PER_PAGE) {
		if(count($array_id)>0){
			$string_id = implode(',',$array_id);
			return $this->getObjects($page, 'cid IN('.$string_id.')' . ' AND status = 1', $sort, $items_per_page);
		}
		return;
	}
			
	function getNumRecordCId($cid) {
		$result = $this->getNumItems('id',"`cid` = '$cid' AND status = 1", $items_per_page = DEFAULT_ADMIN_ROWS_PER_PAGE);
		if($result) return $result;
		return "";
	}
/*-----------------------------------------------------------------------*
* Function: getRelatedProduct lay san pham cung loai
* Parameter: WHERE catproduct
* Return: Array Bid of manufacturers
*-----------------------------------------------------------------------*/		
	function getRelatedProduct($page = 1, $id, $sort = array(), $items_per_page = DEFAULT_ADMIN_ROWS_PER_PAGE){
		$news = $this->getObject($id);
		if($news){
			$condition = 'cid = ' . $news->getField('cid') . ' AND id NOT IN('. $id .')';
			return $this->getObjects($page, $condition, $sort, $items_per_page);
		}
		return;
	}
/*-----------------------------------------------------------------------*
* Function: cleanTrash
* Parameter: WHERE condition
* Return: true or false
*-----------------------------------------------------------------------*/
	function cleanTrash($condition = '1=1'){
		$dem = 0;
		$objectDelete = $this->getObjects(1, $condition, '', '');
		foreach($objectDelete as $object){
			$ok1 = $object->deleteAvatar();
			$ok3 = $object->deleteVideo();
			$ok2 = $this->delete("id = " . $object->getField('id'));
			if(!$ok1 && !$ok2 && !$ok3) $dem++;
		}
		return $dem==0?true:false;
	}	
}
?>